#!/bin/bash

#NOTE!!!! running under bash recommended.
#         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#                       ^^^^
# In mpiexec command, $1 stands for the count of started processes.
# If you are using extra arguments, insert $2, $3, ... after ./exe
# and enter "run <proc nb> <your arguments>". You will be able to
# to get access to them in your code through Sdf::argc and
# Sdf::argv[1], Sdf::argv[2], ...


#When mpiexec hangs, type ctrl-C to execute exithandler


trap exithandler TERM INT
exithandler()
{
   /bin/cat itrace* > ./trace
   /bin/rm -rf ./itrace*

   /bin/cat ./iexec_report* > ./exec_report
   /bin/rm -rf ./iexec_report*
   more ./exec_report

   echo "Received ctrl-C: quiting"
   exit 1
}


/bin/rm -rf ./trace
/bin/rm -rf ./exec_report
/home/adamo/mpich2-1.0.6p1-install/bin/mpiexec -np $1 ./exe
/bin/cat ./itrace* > ./trace
/bin/rm -rf ./itrace*

/bin/cat ./iexec_report* > ./exec_report
/bin/rm -rf ./iexec_report*
more ./exec_report

